@extends('layout.wechat_frame')

@section('main')

    <header class="mui-bar mui-bar-nav">
        <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
        <h1 class="mui-title">投标报价-需求详细</h1>
    </header>
    <div class="mui-content">
        <ul class="mui-table-view mui-table-view-striped mui-table-view-condensed">
            <li class="mui-table-view-cell">

                <?php
                $goods = json_decode($bid->goods_static);
                ?>

                <h5 class="ips-text-blue"><marquee  scrollAmount="3" width="345px">{{ $goods->name }}采购标书报价将在{{ $bid->offer_stop }}结束</marquee></h5>
                <h5 ><span>结束倒计时：</span><span class="ips-text-red"><span class="colockbox" id="colockbox-global"><span class="hour">00</span>:<span class="minute">00</span>:<span class="second">00</span></span></span></h5>
                <h4 class="mui-ellipsis">质量指标:</h4>
			<textarea id="textarea" class="ips-textarea" rows="5" placeholder="" readonly>{{ $goods->quality_standard }}</textarea>
            </li>
         </ul>
    </div>

    @foreach ($demands as $k=>$demand)
        <?php
        $assign_rule = json_decode($demand->assign_rule);
        $assign_rule_data = $assign_rule->rules;
        $assign_rule_data = json_decode($assign_rule_data, true);
        $assign = array_filter($assign_rule_data);
        $min_assign = min($assign);
        $assign_rule_data = implode('%；', $assign_rule_data).'%';
        ?>


    <div class="mui-content ips-mui-content-no-top">
        <ul class="mui-table-view mui-table-view-striped mui-table-view-condensed">
            <li class="mui-table-view-cell mui-collapse">
                <h5 ><span class="ips-span-first-long">公司名/交货地点</span><span>采购数量</span></h5>
                <a class="mui-navigate-right" href="#"><h5><span class="ips-span-first-long">{{ $demand->company->name }}</span><span>{{ strval((float)$demand->quantity) }}</i> {{ $goods->unit }}</span></h5></a>
                <div class="mui-collapse-content">

                    <?php
                    // lvze add 20160908 取得 到货方式 交货地点
                    // 如果交货方式中没有设定地点 则显示 公司交货地点
                    $delivery_mode = \App\DeliveryMode::orderBy('created_at')->whereNull('deleted_at')->where('id', $demand->delivery_mode_id)->first();
                    ?>
                    @if(!empty($delivery_mode) and !is_null($delivery_mode->delivery_place))
                            <h5 ips-row-h5>交货地点：{{ $delivery_mode->delivery_place}}</h5>
                    @else
                            <h5 ips-row-h5>交货地点：{{ $demand->company->delivery_address }}</h5>
                    @endif

                    <input type="hidden" name="demand_id[]" value="{{ $demand->id }}" />
                    <h5 class="mui-ellipsis ips-row-h5" >发票/付款方式：{{ $demand->invoice }} {{ $demand->payment }}</h5>
                    <h5 class="mui-ellipsis ips-row-h5" >分配方案：{{ $assign_rule->name }}【{{ $assign_rule_data }}】</h5>
                    <h5 class="mui-ellipsis ips-row-h5" >报价有效期：招投标结束后{{ $demand->price_validity }}小时</h5>
                    <h5 class="mui-ellipsis ips-row-h5" >交货日期：{{ $demand->delivery_date_start }} 至 {{ $demand->delivery_date_stop }}</h5>
                </div>
            </li>

            <?php
            $offer = $demand->offer()->where('user_id', auth()->user()->id)->first();
            ?>

            <li class="mui-table-view-cell">
                <h5 ><span class="ips-span-first">我的报价</span><span>报价时间</span></h5>
                <h5 >
                    @if(!empty($offer) and is_null($offer->reason))
                        <span class="ips-span-first">{{ strval((float)$offer->price) }}</span><span> {{ $offer->updated_at }}</span>
                    @endif
                </h5>
                <div>

                    @if(!empty($offer) and is_null($offer->reason))
                        <a class="ips-row-btn mui-btn-danger" href ="javascript:return false;" style="opacity: 0.5">不参与</a>
                    @else
                        <a class="ips-row-btn mui-btn-danger" href="{{ route('bidQuote.bqDetail.doRefuse', ['demand' => $demand->id])}}">不参与</a>
                    @endif

                    @if(!empty($offer))
                        @if(!is_null($offer->reason))
                            <a class="ips-row-btn mui-btn-warning right-long" href ="javascript:return false;" style="opacity: 0.5">改价</a>
                        @else
                            <a class="ips-row-btn mui-btn-warning right-long" href="{{ route('bidQuote.bqDetail.doWork', ['demand' => $demand->id])}}">改价</a>
                        @endif
                    @else
                        <a class="ips-row-btn mui-btn-primary right-long" href="{{ route('bidQuote.bqDetail.doWork', ['demand' => $demand->id])}}">报价</a>
                 @endif


                </div>
            </li>
        </ul>
    </div>
   @endforeach

@section('js')
    <script type="text/javascript">

    // 倒计时
    function countDown(end,start,id){
        //var day_elem = $(id).find('.day');
        var hour_elem = $(id).find('.hour');
        var minute_elem = $(id).find('.minute');
        var second_elem = $(id).find('.second');
        var end_time = new Date(end).getTime(),//月份是实际月份-1
        sys_second = (end_time-new Date(start).getTime())/1000;
        var timer = setInterval(function(){
                        if (sys_second > 1) {
                            sys_second -= 1;
                            //var day = Math.floor((sys_second / 3600) / 24);
                            var hour = Math.floor((sys_second / 3600) % 24);
                            var minute = Math.floor((sys_second / 60) % 60);
                            var second = Math.floor(sys_second % 60);
                            //day_elem && $(day_elem).text(day);//计算天
                            $(hour_elem).text(hour<10?"0"+hour:hour);//计算小时
                            $(minute_elem).text(minute<10?"0"+minute:minute);//计算分钟
                            $(second_elem).text(second<10?"0"+second:second);//计算秒杀
                        } else {
                            clearInterval(timer);
                        }
                    }, 1000);
    }

    $(document).ready(function() {

    $.get('{{ route('system.datetime') }}', function (datetime) {
        countDown('{{ str_replace('-', '/', $bid->offer_stop) }}', datetime.replace(/-/g, '/'), '#colockbox-global');
        });
    });

    // 报价按钮跳转
    var buttonList = document.getElementsByClassName('ips-row-btn mui-btn-primary right-long');
    for (var i=0; i<buttonList.length; i++) {
        // 跳转页面
        buttonList[i].addEventListener('tap', function(event) {
            mui.openWindow(this.href);
        }, false);
    }

    </script>

@stop